package com.example.thread;

/**
 * Created by Quincy on 2018/10/12.
 */
public class ThreadCount {

    int count = 0;
    public static void man(String[] args){
        ThreadCount threadCount = new ThreadCount();
        MyRunnable myRunnable = threadCount.new MyRunnable();
        for (int i = 0; i < 4; i++)
            new Thread(myRunnable).start();
    }

    class MyRunnable implements Runnable{

        @Override
        public void run() {
            while (true){
                synchronized (MyRunnable.class){
                    if (count >= 1000)
                        break;
                    System.out.println("count:"+ ++count);
                    Thread.yield();
                }
            }
        }
    }
}
